package com.platform.hjt.crm.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hjt.tools.dao.Page;
import com.hjt.tools.dao.PropertyFilter;
import com.platform.hjt.base.controller.BaseController;
import com.platform.hjt.base.controller.ReturnBody;
import com.platform.hjt.base.log.AopConstant;
import com.platform.hjt.base.log.AopLog;
import com.platform.hjt.crm.model.CrmCustomerInfo;
import com.platform.hjt.crm.service.CrmCustomerInfoService;

@Controller
@RequestMapping(value="/crmCustomerInfo")
public class CrmCustomerInfoController extends BaseController{

	@Resource
	private CrmCustomerInfoService crmCustomerInfoService;
	
	@RequestMapping(value="/crmCustomerInfo_list.html")
	public String crmCustomerInfoListPage(){
		return "page/admin/crmCustomerInfo/crmCustomerInfo_list";
	}
	
	
	@RequestMapping(value="/crmCustomerInfo_list.do")
	@ResponseBody
	@AopLog(aopType=AopConstant.BEFORE)
	public Page<CrmCustomerInfo> crmCustomerInfoListDo(Page<CrmCustomerInfo>page){
		List<PropertyFilter>  propertyFilterList = PropertyFilter.buildFromHttpRequest(getRequest());
		propertyFilterList.add(new PropertyFilter("EQB_isDel", "false"));
		return crmCustomerInfoService.getCrmCustomerInfoList(page, propertyFilterList);
	}
	
	@RequestMapping(value="/crmCustomerInfo_edit.html")
	public String crmCustomerInfoEditPage(HttpServletRequest request, Model model, String id){
		if(StringUtils.isNotBlank(id)){
			model.addAttribute("crmCustomerInfo", crmCustomerInfoService.getCrmCustomerInfo("crmCustomerInfoId", id));
		}
		
		return "page/admin/crmCustomerInfo/crmCustomerInfo_edit";
	}
	
	@RequestMapping(value="/crmCustomerInfo_detail_{id}.html")
	public String crmCustomerInfoDetailPage(Model model, @PathVariable String id){
		model.addAttribute("crmCustomerInfo", crmCustomerInfoService.getCrmCustomerInfo("crmCustomerInfoId", id));
		return "page/admin/crmCustomerInfo/crmCustomerInfo_detail";
	}
	
	@RequestMapping(value="/crmCustomerInfo_edit.do")
	@ResponseBody
	public ReturnBody crmCustomerInfoEditDo(@Valid @ModelAttribute("crmCustomerInfo") CrmCustomerInfo crmCustomerInfo, BindingResult result){
		if(result.hasErrors()){
			return new ReturnBody(false, result.getAllErrors().get(0).getDefaultMessage());
		}
		return crmCustomerInfoService.saveCrmCustomerInfo(crmCustomerInfo);
	}
	
	@RequestMapping(value="/crmCustomerInfo_del_{id}.do")
	@ResponseBody
	public ReturnBody crmCustomerInfoDelDo(@PathVariable String id){
		return crmCustomerInfoService.delCrmCustomerInfo(new CrmCustomerInfo(id));
	}
	
	
}
